$(function(){
    var global_keyhandler = function(e){
        //if(typeof console.log != 'undefined') console.log(e.keyCode);
        if(e.keyCode == 27){
            $("#container").toggleClass("fixed");
            //return false;
        }
        if(e.keyCode == 112){ //F1
            document.location = "?";
            return false;
        }
        
        if(e.keyCode == 113){
            $("textarea").htmlarea({
                toolbar: [
                    ["html", "bold", "italic", "underline", "|", "forecolor"],
                    ["p", "h1", "h2", "h3", "h4", "h5", "h6"],
                    ["link", "unlink", "|", "image"]                    
                ]
            });
            return false;
        }
        if(e.keyCode == 114){
            //$(".jHtmlArea").remove();
            $("textarea").show();
            return false;
        }
        
        if(e.keyCode == 192 && e.ctrlKey){      
            $.colorbox({inline:true, href:'#console', opacity: 0.5,
                onComplete: function(){
                    $("textarea.command").focus();
                    $("textarea.command").keydown(function(e){
                        if(e.keyCode == 13 && e.ctrlKey){
                            document.location = "?lego_home=command&command="+encodeURIComponent($("textarea.command").val());
                        }
                    });
                }
            });
            return false;
        }
        return true;
    }
    
    $("*").keydown(global_keyhandler)
    
    $("textarea").keyup(function(e){
        $(this).css("height", this.scrollHeight);
    })
    
    
    if($(".sqlview table").width() > 690){
        $("#container").removeClass("fixed");
    }

});